/*     */ package com.chinapay.secss.util;
/*     */ 
/*     */ import com.enation.app.javashop.framework.util.DateUtil;
/*     */ import java.security.KeyFactory;
/*     */ import java.security.PublicKey;
/*     */ import java.security.Signature;
/*     */ import java.security.spec.X509EncodedKeySpec;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class PayUtil
/*     */ {
/*  20 */   private static int isload = 0;
/*     */ 
/*     */   
/*  23 */   private static String[] licenses = null;
/*     */ 
/*     */   
/*  26 */   private static String newPublicKey = "30819f300d06092a864886f70d010101050003818d0030818902818100996b56ccc3703e6fa979ee474ab95c91c25a8c8e7454d2fd95207a57b92a1fe02a71d3aff40b3d56f6f5715245e4629767898ea8023553f18e442e10f23ded13a77ca33056a4bb072664e6dc5757d304f9c6ac8f204ed65c727c2a71c49b4978da9dab9224bf7e30e33e3a6b4c8f4315a523e468de4c8eab1e1dfe785d4f39190203010001";
/*     */   
/*     */   private static boolean verifySign(String hexPublicKey, String signedStr, String str) {
/*     */     try {
/*  30 */       X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(HexUtils.hexStrToBytes(hexPublicKey));
/*  31 */       KeyFactory keyFactory = KeyFactory.getInstance("RSA");
/*  32 */       PublicKey publicKey = keyFactory.generatePublic(x509EncodedKeySpec);
/*  33 */       byte[] signed = HexUtils.hexStrToBytes(signedStr);
/*     */       
/*  35 */       Signature signature = Signature.getInstance("MD5withRSA");
/*  36 */       signature.initVerify(publicKey);
/*  37 */       signature.update(str.getBytes());
/*  38 */       return signature.verify(signed);
/*  39 */     } catch (Exception e) {
/*  40 */       return false;
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public static void load(List<String> list) {
/*  47 */     licenses = list.<String>toArray(new String[list.size()]);
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public static boolean verify(String domain) {
/*     */     try {
/*  59 */       if (licenses == null || licenses.length == 0) {
/*  60 */         return false;
/*     */       }
/*  62 */       for (String license : licenses) {
/*     */         try {
/*  64 */           if (verifyLicense(license, domain)) {
/*  65 */             return true;
/*     */           }
/*  67 */         } catch (Exception exception) {}
/*     */       }
/*     */     
/*  70 */     } catch (Exception exception) {}
/*     */     
/*  72 */     return false;
/*     */   }
/*     */ 
/*     */   
/*     */   private static boolean verifyLicense(String license, String domain) {
/*  77 */     String[] ar = license.split(",");
/*  78 */     int size = ar.length;
/*  79 */     if (size != 2) {
/*  80 */       return false;
/*     */     }
/*     */     
/*  83 */     String sign = ar[0];
/*  84 */     String text = ar[1];
/*     */     
/*  86 */     boolean signResult = verifySign(newPublicKey, sign, text);
/*     */     
/*  88 */     if (signResult) {
/*  89 */       text = JiaMiUtil.decryptCode(text);
/*  90 */       return fenxi(text, domain);
/*     */     } 
/*     */     
/*  93 */     return false;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private static boolean fenxi(String str, String checkDomian) {
/* 100 */     String version = null;
/* 101 */     String type = null;
/* 102 */     String domain = null;
/* 103 */     String timeout = null;
/* 104 */     String ipstart = null;
/* 105 */     String ipend = null;
/* 106 */     String[] arr = str.split(",");
/*     */     
/* 108 */     if (arr.length > 1) {
/* 109 */       version = getValue(arr[0], "version");
/*     */     }
/*     */     
/* 112 */     if (arr.length > 2) {
/* 113 */       type = getValue(arr[1], "type");
/*     */     }
/*     */     
/* 116 */     if (arr.length > 3) {
/* 117 */       domain = getValue(arr[2], "domain");
/*     */     }
/*     */     
/* 120 */     if (arr.length >= 4) {
/* 121 */       timeout = getValue(arr[3], "timeout");
/*     */     }
/* 123 */     if (arr.length >= 5) {
/* 124 */       ipstart = getValue(arr[4], "ipstart");
/*     */     }
/* 126 */     if (arr.length >= 6) {
/* 127 */       ipend = getValue(arr[5], "ipend");
/*     */     }
/*     */ 
/*     */     
/* 131 */     if ("6.5".equals(version)) {
/*     */       
/* 133 */       boolean domainResult = false;
/* 134 */       boolean timeResult = false;
/*     */       
/* 136 */       domainResult = checkDomain(type, checkDomian, domain, ipstart, ipend);
/*     */       
/* 138 */       if (!"nolimit".equals(timeout)) {
/* 139 */         long now = DateUtil.getDateline();
/* 140 */         long timeoutL = Long.valueOf(timeout).longValue();
/* 141 */         if (now >= timeoutL) {
/* 142 */           timeResult = false;
/*     */         } else {
/* 144 */           timeResult = true;
/*     */         } 
/*     */       } else {
/* 147 */         timeResult = true;
/*     */       } 
/*     */       
/* 150 */       return (domainResult && timeResult);
/*     */     } 
/*     */ 
/*     */     
/* 154 */     return false;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   private static boolean checkDomain(String type, String currentDomain, String enableDomain, String ipstart, String ipend) {
/* 160 */     boolean domainResult = false;
/*     */ 
/*     */     
/* 163 */     if ("1".equals(type) && 
/* 164 */       currentDomain.contains(enableDomain)) {
/* 165 */       domainResult = true;
/*     */     }
/*     */ 
/*     */ 
/*     */     
/* 170 */     if ("0".equals(type) && 
/* 171 */       currentDomain.equals(enableDomain)) {
/* 172 */       domainResult = true;
/*     */     }
/*     */ 
/*     */ 
/*     */     
/* 177 */     if ("2".equals(type)) {
/* 178 */       long checkip = ipToLong(currentDomain);
/* 179 */       long startip = ipToLong(ipstart);
/* 180 */       long endip = ipToLong(ipend);
/*     */       
/* 182 */       if (startip <= checkip && checkip <= endip) {
/* 183 */         domainResult = true;
/*     */       }
/*     */     } 
/* 186 */     return domainResult;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   private static String getValue(String str, String pre) {
/* 192 */     if (str.startsWith(pre)) {
/* 193 */       String[] arr = str.split(":");
/* 194 */       if (arr.length <= 1) {
/* 195 */         return null;
/*     */       }
/* 197 */       return arr[1];
/*     */     } 
/*     */     
/* 200 */     return null;
/*     */   }
/*     */ 
/*     */   
/*     */   private static long ipToLong(String strIp) {
/* 205 */     long[] ip = new long[4];
/*     */     
/* 207 */     int position1 = strIp.indexOf(".");
/* 208 */     int position2 = strIp.indexOf(".", position1 + 1);
/* 209 */     int position3 = strIp.indexOf(".", position2 + 1);
/*     */     
/* 211 */     ip[0] = Long.parseLong(strIp.substring(0, position1));
/* 212 */     ip[1] = Long.parseLong(strIp.substring(position1 + 1, position2));
/* 213 */     ip[2] = Long.parseLong(strIp.substring(position2 + 1, position3));
/* 214 */     ip[3] = Long.parseLong(strIp.substring(position3 + 1));
/* 215 */     return (ip[0] << 24L) + (ip[1] << 16L) + (ip[2] << 8L) + ip[3];
/*     */   }
/*     */ 
/*     */   
/*     */   private static String longToIP(long longIp) {
/* 220 */     StringBuffer sb = new StringBuffer("");
/*     */     
/* 222 */     sb.append(String.valueOf(longIp >>> 24L));
/* 223 */     sb.append(".");
/*     */     
/* 225 */     sb.append(String.valueOf((longIp & 0xFFFFFFL) >>> 16L));
/* 226 */     sb.append(".");
/*     */     
/* 228 */     sb.append(String.valueOf((longIp & 0xFFFFL) >>> 8L));
/* 229 */     sb.append(".");
/*     */     
/* 231 */     sb.append(String.valueOf(longIp & 0xFFL));
/* 232 */     return sb.toString();
/*     */   }
/*     */ }


/* Location:              C:\Users\Administrator\Downloads\jd-gui-windows-1.6.6\jd-gui-windows-1.6.6\chinapay-secure-1.5.1.jar!\com\chinapay\secs\\util\PayUtil.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.3
 */